package com.zhentao.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhentao.model.common.dtos.ResponseResult;
import com.zhentao.model.pojo.car.ProvinceCars;
import com.zhentao.model.pojo.car.Vo.ProvinceCarsVo;
import com.zhentao.service.ProvinceCarsService;
import com.zhentao.mapper.ProvinceCarsMapper;
import org.apache.commons.lang.StringUtils;
import org.checkerframework.checker.units.qual.C;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author 22115
* @description 针对表【province_cars】的数据库操作Service实现
* @createDate 2024-12-18 20:56:13
*/
@Service
public class ProvinceCarsServiceImpl extends ServiceImpl<ProvinceCarsMapper, ProvinceCars>
    implements ProvinceCarsService{

    @Override
    public ResponseResult licensePlateInfoService() {
        List<ProvinceCars> list = this.list();
        return ResponseResult.okResult(list);
    }

    @Override
    public ResponseResult getCarsProvince(String carNo) {
        if (!StringUtils.isNotBlank(carNo)){
            return ResponseResult.errorResult(500, "参数不能为空");
        }

        char c = carNo.charAt(0);
        System.out.println("==="+c);
        String CarNo = Character.toString(c);
        String remainingCarNo = carNo.substring(1);
        List<ProvinceCars> list = this.list();
        for (ProvinceCars provinceCars : list) {
            if (provinceCars.getProvince().equals(CarNo)){
                ProvinceCarsVo provinceCarsVo = new ProvinceCarsVo();
                BeanUtils.copyProperties(provinceCars,provinceCarsVo);

                provinceCarsVo.setCarNo(remainingCarNo);
                return ResponseResult.okResult(provinceCarsVo);
            }
        }

        return ResponseResult.errorResult(500, "参数错误");
    }
}




